﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Fast.Framework.Interfaces;
using Fast.Framework.Models;

namespace Fast.Framework
{

    /// <summary>
    /// 删除建造者
    /// </summary>
    public class DeleteBuilder : IDeleteBuilder
    {

        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get; set; }

        /// <summary>
        /// 参数
        /// </summary>
        public Dictionary<string, object> Parameters { get; }

        /// <summary>
        /// 条件
        /// </summary>
        public List<string> Where { get; }


        /// <summary>
        /// 构造方法
        /// </summary>
        public DeleteBuilder()
        {
            Where = new List<string>();
            Parameters = new Dictionary<string, object>();
        }

        /// <summary>
        /// 到字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append($"DELETE FROM {TableName}");
            if (Where.Count > 0)
            {
                sb.Append($" WHERE {string.Join(" AND ", Where)}");
            }
            //Console.WriteLine(sb.ToString().Trim());
            return sb.ToString().Trim();
        }
    }
}
